# by Jingyue

'''
Read the table from <fin>.
Returns a 2D array of strings, # of rows, and # of colomns.
The caller opens and closes the file.
'''

import sys
import csv

def read_table(fin):
    MAX_N = 256
    a = [['' for j in range(MAX_N)] for i in range(MAX_N)]

    m = 0
    n = 0
    fin = csv.reader(fin)
    for row in fin:
        if len(row) > n:
            n = len(row)
            if n > MAX_N:
                print >> sys.stderr, '# of cols is out of bound'
                exit(-1)
        for j in range(len(row)):
            a[m][j] = row[j]
        m += 1
        if m > MAX_N:
            print >> sys.stderr, '# of rows is out of bound'
            exit(-1)

    print >> sys.stderr, 'Dimension: m =', m, ', n =', n

    return a, m, n


